import {mockData} from './mock'
import {BASE_URL} from "../../constant/index";
import {getRoomTags} from '../../utils/tool'

Page({
    data: {
        roomList: [],
        code: ''
    },
    chooseRoomConfirm(ev) {
        const {detail} = ev
        const refTarget = this.selectComponent('#mealPopup')
        if (!refTarget) return
        refTarget?.open(detail)
    },
    generateRoomList(list,code) {
        this.setData({
            roomList: list.map(item => {
                item.image = `${BASE_URL}${item.image}`
                item.room_tags = getRoomTags(item.room_tags)
                item.qr_code = code
                return item
            })
        })
    },
    onLoad: function () {
        if (!this.eventChannel) {
            this.eventChannel = this.getOpenerEventChannel()
            this.eventChannel.on && this.eventChannel.on('getData', this.getData)
        }
    },
    onUnload() {
        if (this.eventChannel) {
            this.eventChannel.off && this.eventChannel.off('getData', this.getData)
            this.eventChannel = null
        }
    },

    getData({data,codeValue}) {
        this.generateRoomList(data,codeValue)
    }
});
